<!-- Copyright 2014 Google Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// -->
<!DOCTYPE html>
<title>Unit Test of e2e.FastModulus</title>
<script src="../../../../../javascript/closure/base.js"></script>
<script src="test_js_deps-runfiles.js"></script>
<script>
  goog.require('goog.testing.jsunit');
  goog.require('e2e.BigNum');
  goog.require('e2e.bigNumTestData');
  goog.require('e2e.BigPrimeNum');
  goog.require('e2e.FastModulus');
</script>
<script>

var P256 = new e2e.BigNum(e2e.bigNumTestData.P_256);
var P512 = P256.multiply(P256);


//
// Note that additional tests have moved to ecc/fastmodulus_test.html
//

/**
 * Ensure that FastModulus.FFFFFF works on all bignums whose high
 * 24 bits are 1, no matter what the alignment.
 */
function testModulusFFFFFF() {
  var value = new e2e.BigPrimeNum(e2e.bigNumTestData.N);
  for (var i = 0; i < 24; i++) {
    var modulus = value.shiftLeft(i);
    var value1 = new e2e.FastModulus.FFFFFF(modulus).residue(P512);
    var value2 = P512.mod(modulus);
    assertTrue(value1.isEqual(value2));
  }
}

/**
 * Ensure that FastModulus.Ox1000000
 * works on all bignums whose high
 * 24 bits are 1, no matter what the alignment.
 */
function testModulus1000000() {
  var value = new e2e.BigPrimeNum([1, 0, 0, 0, 0x88, 0x88, 0x89]);
  for (var i = 0; i < 24; i++) {
    var modulus = value.shiftLeft(i);
    var value1 = new e2e.FastModulus.Ox1000000(modulus).residue(P512);
    var value2 = P512.mod(modulus);
    assertTrue(value1.isEqual(value2));
  }
}



</script>
